package com.qf.fmall2302.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.fmall2302.product.entity.ProductParams;
import com.qf.fmall2302.product.service.IProductCommentsService;
import com.qf.fmall2302.product.service.IProductParamsService;
import com.qf.fmall2302.product.service.IProductService;
import com.qf.fmall2302.utils.FmallConstants;
import com.qf.fmall2302.vo.PageVo;
import com.qf.fmall2302.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * <p>
 * 商品 商品信息相关表：分类表，商品图片表，商品规格表，商品参数表 前端控制器
 * </p>
 *
 * @author dongjl
 * @since 2023-08-23
 */
@RestController
@RequestMapping("/product")
@CrossOrigin
@Slf4j
public class ProductController {

    @Autowired
    IProductService productService;

    @Autowired
    IProductParamsService productParamsService;

    @Autowired
    IProductCommentsService productCommentsService;


    @GetMapping("/detail-commontscount/{productid}")
    public ResultVo detailCommontscount(@PathVariable("productid") String productid){

        log.info("入参为:productid={}",productid);
        HashMap<String,Object> data = productCommentsService.detailCommontscountBysql(productid);
        return ResultVo.ok(FmallConstants.SUCCESS_CODE, FmallConstants.SUCCESS_MSG, data);

    }

    @GetMapping("/detail-commonts/{productid}")
    public ResultVo detailCommonts(@PathVariable("productid") String productid
    ,Integer pageNum,Integer limit){
        log.info("入参为:productid={},pageNum={},limit={}",productid,pageNum,limit);

        PageVo data = productCommentsService.detailCommonts(productid,pageNum,limit);
        return ResultVo.ok(FmallConstants.SUCCESS_CODE, FmallConstants.SUCCESS_MSG, data);
    }


    @GetMapping("/detail-params/{productid}")
    public ResultVo detailParams(@PathVariable("productid") String productid ){
        log.info("入参为:productid={}",productid);
        ProductParams params = productParamsService.getOne(new QueryWrapper<ProductParams>().eq("product_id", productid));
        return ResultVo.ok(FmallConstants.SUCCESS_CODE, FmallConstants.SUCCESS_MSG, params);
    }

    @GetMapping("/detail-info/{productid}")
    public ResultVo detailInfo(@PathVariable("productid") String productid ){
        log.info("入参为:productid={}",productid);
        HashMap<String,Object> data = productService.detailInfo(productid);
        return ResultVo.ok(FmallConstants.SUCCESS_CODE, FmallConstants.SUCCESS_MSG, data);
    }

}
